# = test.admin.3.rb - Admin, User Email Settings Test
# 
# See LICENSE.txt for licensing details.
#
# == Description
# This will test the email settings for a user in the membership section.
#


$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') if $0 == __FILE__
require 'watir'
include Watir
require 'test/unit'
require '../watir.config.rb'

class TC_AdminUserEmailSettings_test < Test::Unit::TestCase
      
      def startup
        @@ie = Watir::IE.start($SITE_URL)
      end
    
      def ie
        if defined? @@ie
          @@ie
        else
          startup
        end
      end
      

    def test_01_verifyHomeText
        assert(ie.contains_text(/Community Server/))		
    end
      
    def test_02_verifyLoginLinksExist
      if !(ie.link(:text, 'Sign in').exists?)
        ie.goto($SITE_URL + 'logout.aspx')
        ie.refresh
        ie.goto($SITE_URL)
        ie.refresh
      end
	  end
    
    def test_03_navigateToLogin
      ie.link(:text, 'Sign in').click
      assert(ie.contains_text("Sign in name"))
    end
	  
	  def test_04_populateLoginForm
      ie.text_field(:id, /username$/).value = $ADMIN_USER
      assert(ie.text_field(:id, /username$/).verify_contains($ADMIN_USER))
      
      ie.text_field(:id, /password$/).value = $ADMIN_PASSWORD
      assert(ie.text_field(:id, /password$/).verify_contains($ADMIN_PASSWORD))
	  end
	  
    def test_05_submitLoginForm
      ie.link(:id, /loginButton$/).click
      test_01_verifyHomeText
    end
    
    def test_06_verifyControlPanel
      assert(ie.link(:text, /Control Panel/).exists?)
      ie.link(:text, /Control Panel/).click
      assert(ie.contains_text(/Community Server Announcements/))
      assert(ie.link(:text, /Administration/).exists?)
      ie.link(:text, /Administration/).click
      assert(ie.contains_text(/Community Server Announcements/))
    end
    
    def test_07_verifyControlPanelTabBarLinks
      assert_equal $SITE_URL + 'controlpanel/default.aspx', ie.link(:text, 'Dashboard').href
      assert_equal $SITE_URL + 'controlpanel/blogs', ie.link(:text, 'My Blogs').href
      assert_equal $SITE_URL + 'controlpanel/photos/', ie.link(:text, 'My Photos').href
      assert_equal $SITE_URL + 'controlpanel/files', ie.link(:text, 'My Files').href
      assert_equal $SITE_URL + 'controlpanel/moderation', ie.link(:text, 'Forums Moderation').href
      assert_equal $SITE_URL + 'controlpanel/Setup.aspx', ie.link(:text, 'Administration').href
      assert_equal $SITE_URL + 'controlpanel/Reporting/default.aspx', ie.link(:text, 'Reporting').href
    end
    
    def test_08_navigateToMembership
      ie.goto($SITE_URL + 'ControlPanel/Membership/membersearch.aspx?SelectedNavItem=BrowseMembers')
      
      assert(ie.link(:text, 'admin').exists?)
      assert(ie.link(:id, /_logout$/).exists?)
      assert(ie.link(:text, 'Help').exists?)
      assert(ie.link(:text, 'Inbox').exists?)
      assert(ie.link(:text, 'Exit Control Panel and Return to Site').exists?)
      assert(ie.link(:text, 'Dashboard').exists?)
      assert(ie.link(:text, 'My Blogs').exists?)
      assert(ie.link(:text, 'My Photos').exists?)
      assert(ie.link(:text, 'My Files').exists?)
      assert(ie.link(:text, 'Forums Moderation').exists?)
      assert(ie.link(:text, 'Administration').exists?)
      assert(ie.link(:text, 'Reporting').exists?)
      assert(ie.link(:text, 'Find People').exists?)
      assert(ie.link(:text, 'Browse People').exists?)
      assert(ie.link(:text, 'Create New Account').exists?)
      assert(ie.link(:text, 'Manage All Roles').exists?)
      assert(ie.link(:text, 'New Registration Settings').exists?)
      assert(ie.link(:text, 'Global Account Profile Settings').exists?)
      assert(ie.link(:text, 'Member List Settings').exists?)
      assert(ie.link(:text, 'Cookie and Anonymous Settings').exists?)
      assert(ie.link(:text, 'Global Avatar Settings').exists?)
    end
    
    def test_09_confirmFieldsExist
      assert(ie.text_field(:id, /_searchText$/).exists?)
      
      assert(ie.select_list(:id, /_memberSortDropDown$/).exists?)
      assert(ie.select_list(:id, /_sortOrderDropDown$/).exists?)
      assert(ie.select_list(:id, /_joinedDateComparer$/).exists?)
      assert(ie.select_list(:id, /_lastPostDateComparer$/).exists?)
      assert(ie.select_list(:id, /_searchRole$/).exists?)
      assert(ie.select_list(:id, /_searchType$/).exists?)
      assert(ie.select_list(:id, /_currentAccountStatus$/).exists?)
      assert(ie.select_list(:id, /TaskRegion_PageList$/).exists?)
    end
    
    def test_10_navigateToEditAdminAccount
      ie.goto($SITE_URL + 'ControlPanel/Membership/UserEdit.aspx?UserID=2100')
      
      assert(ie.link(:text, 'admin').exists?)
      assert(ie.link(:id, /_logout$/).exists?)
      assert(ie.link(:text, 'Help').exists?)
      assert(ie.link(:text, 'Inbox').exists?)
      assert(ie.link(:text, 'Exit Control Panel and Return to Site').exists?)
      assert(ie.link(:text, 'Dashboard').exists?)
      assert(ie.link(:text, 'My Blogs').exists?)
      assert(ie.link(:text, 'My Photos').exists?)
      assert(ie.link(:text, 'My Files').exists?)
      assert(ie.link(:text, 'Forums Moderation').exists?)
      assert(ie.link(:text, 'Administration').exists?)
      assert(ie.link(:text, 'Reporting').exists?)
      assert(ie.link(:text, 'Find People').exists?)
      assert(ie.link(:text, 'Browse People').exists?)
      assert(ie.link(:text, 'Create New Account').exists?)
      assert(ie.link(:text, 'Manage All Roles').exists?)
      assert(ie.link(:text, 'New Registration Settings').exists?)
      assert(ie.link(:text, 'Global Account Profile Settings').exists?)
      assert(ie.link(:text, 'Member List Settings').exists?)
      assert(ie.link(:text, 'Cookie and Anonymous Settings').exists?)
      assert(ie.link(:text, 'Global Avatar Settings').exists?)
    end
    
    def test_11_confirmEditAccountRadioButtons
      assert(ie.radio(:id, /isAvatarApproved_0$/).exists?)
      assert(ie.radio(:id, /isAvatarApproved_1$/).exists?)
      assert(ie.radio(:id, /forceLogin_0$/).exists?)
      assert(ie.radio(:id, /forceLogin_1$/).exists?)
      assert(ie.radio(:id, /isIgnored_0$/).exists?)
      assert(ie.radio(:id, /isIgnored_1$/).exists?)
      assert(ie.radio(:id, /enableBirthdayRadioButton$/).exists?)
      assert(ie.radio(:id, /disableBirthdayRadioButton$/).exists?)
      assert(ie.radio(:id, /gender_0$/).exists?)
      assert(ie.radio(:id, /gender_1$/).exists?)
      assert(ie.radio(:id, /gender_2$/).exists?)
      assert(ie.radio(:id, /enableAvatar_0$/).exists?)
      assert(ie.radio(:id, /enableAvatar_1$/).exists?)
      assert(ie.radio(:id, /enableInk_0$/).exists?)
      assert(ie.radio(:id, /enableInk_1$/).exists?)
      assert(ie.radio(:id, /enableDisplayNames_0$/).exists?)
      assert(ie.radio(:id, /enableDisplayNames_1$/).exists?)
      assert(ie.radio(:id, /displayInMemberList_0$/).exists?)
      assert(ie.radio(:id, /displayInMemberList_1$/).exists?)
      assert(ie.radio(:id, /EnableCollapsingPanels_0$/).exists?)
      assert(ie.radio(:id, /EnableCollapsingPanels_1$/).exists?)
      assert(ie.radio(:id, /enableEmoticons_0$/).exists?)
      assert(ie.radio(:id, /enableEmoticons_1$/).exists?)
      assert(ie.radio(:id, /enableUserAvtars_0$/).exists?)
      assert(ie.radio(:id, /enableUserAvtars_1$/).exists?)
      assert(ie.radio(:id, /enableUserSignatures_0$/).exists?)
      assert(ie.radio(:id, /enableUserSignatures_1$/).exists?)
      assert(ie.radio(:id, /enableEmail_0$/).exists?)
      assert(ie.radio(:id, /enableEmail_1$/).exists?)
      assert(ie.radio(:id, /enableHtmlEmail_0$/).exists?)
      assert(ie.radio(:id, /enableHtmlEmail_1$/).exists?)
      assert(ie.radio(:id, /enableEmailTracking_0$/).exists?)
      assert(ie.radio(:id, /enableEmailTracking_1$/).exists?)
    end
    
    def test_12_confirmEditAccountFields
      assert(ie.button(:id, /TaskRegion_avatarUpdateButton$/).exists?)
      
      assert(ie.text_field(:id, /TaskRegion_dummyTotalPosts$/).exists?)
      assert(ie.text_field(:id, /TaskRegion_CommonName$/).exists?)
      assert(ie.text_field(:id, /TaskRegion_location$/).exists?)
      assert(ie.text_field(:id, /TaskRegion_occupation$/).exists?)
      assert(ie.text_field(:id, /TaskRegion_interests$/).exists?)
      assert(ie.text_field(:id, /TaskRegion_birthdayDateTimeSelector_text$/).exists?)
      assert(ie.text_field(:id, /TaskRegion_webAddress$/).exists?)
      assert(ie.text_field(:id, /TaskRegion_webLog$/).exists?)
      assert(ie.text_field(:id, /TaskRegion_webGallery$/).exists?)
      assert(ie.text_field(:id, /TaskRegion_avatarUrl$/).exists?)
      assert(ie.text_field(:id, /TaskRegion_privateEmail$/).exists?)
      assert(ie.text_field(:id, /TaskRegion_publicEmail$/).exists?)
      assert(ie.text_field(:id, /TaskRegion_msnIM$/).exists?)
      assert(ie.text_field(:id, /TaskRegion_aolIM$/).exists?)
      assert(ie.text_field(:id, /TaskRegion_yahooIM$/).exists?)
      assert(ie.text_field(:id, /TaskRegion_icq$/).exists?)
    end
    
    def test_14_confirmSelectLists
      assert(ie.select_list(:id, /TaskRegion_accountStatus$/).exists?)
      assert(ie.select_list(:id, /TaskRegion_moderationLevel$/).exists?)
      assert(ie.select_list(:id, /TaskRegion_language$/).exists?)
      assert(ie.select_list(:id, /TaskRegion_timezone$/).exists?)
      assert(ie.select_list(:id, /TaskRegion_dateFormat$/).exists?)
      assert(ie.select_list(:id, /TaskRegion_sortOrder$/).exists?)
      assert(ie.select_list(:id, /TaskRegion_theme$/).exists?)
      assert(ie.select_list(:id, /TaskRegion_FontSize$/).exists?)
      assert(ie.select_list(:id, /TaskRegion_EditorList$/).exists?)
    end
    
    def test_13_confirmSaveChanges
      ie.link(:id, /updateButton$/).click
      
      assert(ie.contains_text('Your options have been successfully saved, but may take several minutes to take effect.'))
    end
    
    def test_99_closeIE
      ie.close
    end
end